package com.fs.groupSeven.controller;

/**
 * @description:
 * @author: fbb
 * @createDate: 2020/10/10 16:14
 */

import com.fs.groupSeven.pojo.Attendance;
import com.fs.groupSeven.pojo.Classroom;
import com.fs.groupSeven.service.AttendanceService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/attendance")
public class AttendanceController {
    @Autowired
    private AttendanceService attendanceService;

    @GetMapping("/attendanceManage")
    public String getAttendanceView() {
        //返回页面
        return "classroomManageFBB/attendanceManagePage";
    }

    @GetMapping("/kuKeMessage")
    public String kuKeMessageView() {
        //返回页面
        return "classroomManageFBB/kuKeMessagePage";
    }
    @RequestMapping("/getAttendanceList")
    @ResponseBody
    public Map<String, Object> getAttendanceList(Integer currentPage, Integer pageSize) {
        PageInfo<Attendance> attendanceByPage = attendanceService.getAttendanceByPage(currentPage, pageSize);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("attendanceList", attendanceByPage.getList());
        //System.out.println(attendanceByPage.getList());
        result.put("message", "获取用户数据成功");
        result.put("totalPage", attendanceByPage.getPages());

        return result;
    }

    @RequestMapping("/getAttendanceKuKeList")
    @ResponseBody
    public Map<String, Object> getAttendanceKuKeList(Integer currentPage, Integer pageSize) {
        PageInfo<Attendance> attendanceByPage = attendanceService.getAttendanceKuKeByPage(currentPage, pageSize);
        Map<String, Object> result = new HashMap<>();
        result.put("code", 0);
        result.put("attendanceList", attendanceByPage.getList());
        //System.out.println(attendanceByPage.getList());
        result.put("message", "获取用户数据成功");
        result.put("totalPage", attendanceByPage.getPages());

        return result;
    }

    @RequestMapping("/addAttendance")
    @ResponseBody
    public Map<String, Object> addAttendance(@RequestBody Attendance attendance) {
        boolean bbb = attendanceService.addOneAttendance(attendance);
        Map<String, Object> result = new HashMap<>();
        if (bbb) {
            result.put("code", 0);
            result.put("message", "添加成功");
        } else {
            result.put("code", -1);
            result.put("message", "添加失败");
        }
        return result;
    }

    @RequestMapping("/queryAttendByMessage")
    @ResponseBody
    public Map<String, Object> queryAttendByMessage(String attendMessage) {
        List<Attendance> attendanceMessageLike = attendanceService.getAttendanceMessageLike(attendMessage);
        Map<String, Object> result = new HashMap<>();
        if (attendanceMessageLike.size() == 0) {
            result.put("code", -1);
            result.put("message", "查无此信息");
        } else {
            result.put("code", 0);
            result.put("attendList", attendanceMessageLike);
            result.put("message", "获取数据成功");
        }
        return result;
    }
}
